
<template>
  <div class="mod-shopBackGoodsAudit">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.name" placeholder="商品名" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-select v-model="dataForm.shopGoodsState" placeholder="请选择商品状态" clearable>
            <el-option
              v-for="item in shopGoodsState"
              :key="item.stateCode"
              :label="item.label"
              :value="item.stateCode">
            </el-option>
          </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()" v-if="isAuth('shopgoods:back:list')">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      style="width: 100%;">

      <el-table-column
        prop="shopGoodId"
        v-if="false"
        header-align="center"
        align="center"
        width="80"
        label="ID">
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        width="400px"
        label="商品">
        <template slot-scope="scope">
          <el-row>
            <el-col :span="5"><img :src="scope.row.firstImgUrl" width="50px" height="50px"/></el-col>
            <el-col :span="8" style="text-align: left;">
              <div>{{scope.row.goodName}}</div>
              <div style="color: deeppink;">￥{{scope.row.firstPrice}}</div>
            </el-col>
          </el-row>
        </template>
      </el-table-column>
      <el-table-column
        prop="typeName"
        header-align="center"
        align="left"
        label="所属分类"
        style="margin-left:40px;">
      </el-table-column>
      <el-table-column
        prop="shopName"
        header-align="center"
        align="left"
        label="所属店铺"
        style="margin-left:20px;">
      </el-table-column>
      <el-table-column
        prop="fnum"
        header-align="center"
        align="center"
        label="规格数量">
      </el-table-column>
      <el-table-column
        prop="state"
        header-align="center"
        align="center"
        label="状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.state === -1" size="small" type="info" class="shopGoodsState">失效</el-tag>
          <el-tag v-if="scope.row.state === 0" size="small" type="warning" class="shopGoodsState">待审核</el-tag>
          <el-tag v-if="scope.row.state === 10" size="small" type="danger" class="shopGoodsState">审核不通过</el-tag>
          <el-tag v-if="scope.row.state === 50" size="small" type="success" class="shopGoodsState">审核通过</el-tag>
          <el-tag v-if="scope.row.state === 100" size="small" class="shopGoodsState">正常</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="optrdate"
        header-align="center"
        align="center"
        label="创建时间"
        width="200px">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" v-if="isAuth('shopgoods:back:info')" @click="viewShopGoodsHandle(scope.row.shopGoodId)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <view-shop-goods v-if="showGoodsVisible" ref="viewGoodsInfo" @refreshDataList="getDataList"></view-shop-goods>
  </div>
</template>

<script>
  import ViewShopGoods from './shopGoodsAudit-view'
  export default {
    data () {
      return {
        dataForm: {
          name: '',
          shopGoodsState: ''
        },
        shopGoodIds: [],
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        showGoodsVisible: false,
        shopGoodsState: [{stateCode: -1, label: '失效'},
                    {stateCode: 0, label: '待审核'},
                    {stateCode: 10, label: '审核不通过'},
                    {stateCode: 50, label: '审核通过'},
                    {stateCode: 100, label: '正常'}]
      }
    },
    components: {
      ViewShopGoods
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/pig-center-biz/shopgoods/back/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'name': this.dataForm.name,
            'state': this.dataForm.shopGoodsState
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 查看
      viewShopGoodsHandle (id) {
        this.showGoodsVisible = true
        this.$nextTick(() => {
          this.$refs.viewGoodsInfo.init(id)
        })
      },
      loadImage (path) {
        return this.$http.adornUrl(`/pig-file/center/file/openImg?url=` + path)
      },
      transGoodsState (row, colum) {
        let obj = this.shopGoodsState.find((item) => {
          return item.stateCode === row.state
        })
        return obj.label
      }
    }
  }
</script>
<style>
.point1{
  cursor:pointer

}
.shopGoodsState{
  width: 80px;
}

</style>
